﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

public partial class Controls_Template_ThongTinFile : System.Web.UI.UserControl
{
    int SIZE_PART = 7;
    class_database db;

    protected void drpPermission_SelectedIndexChanged(object sender, EventArgs e)
    {
        DataTable dt = new DataTable();
        db = new class_database();
        string value = drpPermission.SelectedValue.ToString();
        string idMau = Session["idMau"].ToString();
        string[] _param = { "permission" };
        string[] _value = { value };
        string _where = "idmau = " + idMau + " AND idloaibai = 3";
        db.UpdateRecord("tbl_baiphantich", _param, _value, _where);
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        string idMau = Convert.ToString(Session["idMau"]);
        for (int i = 1; i <= SIZE_PART; i++)
        {
            LoadData(i, idMau);
        }
        SetDisplayEditButton();
        SetTitle(idMau);
    }

    protected void SetDisplayEditButton()
    {
        string sessionUserType = Session["user_type"].ToString();
        string sessionUser = Session["username"].ToString();
        string idMau = Session["idMau"].ToString();
        string nguoiPhanTich = GetNguoiPhanTich(idMau);

        if (sessionUserType == "0")
        {
            drpPermission.Attributes.Add("style", "display: inline-block");
            string sqlGetPermission = "SELECT permission FROM tbl_baiphantich WHERE idloaibai = 3 AND idmau = " + idMau;
            db = new class_database();
            DataTable dt = db.GetDataTable(sqlGetPermission);
            if (dt != null && dt.Rows.Count > 0)
            {
                drpPermission.SelectedValue = dt.Rows[0]["permission"].ToString();
            }
        }

        if (sessionUserType == "0" || nguoiPhanTich.ToLower() == sessionUser)
        {
            btnEditThongTinFile.Attributes.Add("style", "display: inline-block");
            btnDeleteThongTinFile.Attributes.Add("style", "display: inline-block");
        }
    }

    protected void btnEditThongTinFile_Click(object sender, EventArgs e)
    {
        gridThongTinCoBan.Columns[3].Visible = true;
        divSubmitResetThongTinCoBan.Attributes.Add("style", "display: block");
        gridVersion.Columns[3].Visible = true;
        divSubmitResetVersion.Attributes.Add("style", "display: block");
        gridImport.Columns[3].Visible = true;
        divSubmitResetImport.Attributes.Add("style", "display: block");
        gridExport.Columns[3].Visible = true;
        divSubmitResetExport.Attributes.Add("style", "display: block");
        gridViewPE.Columns[3].Visible = true;
        divSubmitResetPE.Attributes.Add("style", "display: block");
        gridSection.Columns[7].Visible = true;
        divSubmitResetSection.Attributes.Add("style", "display: block");
    }

    protected void btnDeleteThongTinFile_Click(object sender, EventArgs e)
    {
        if (hdnCheckConfirm.Value == "yes")
        {
            string idMau = Session["idMau"].ToString();
            db = new class_database();
            string _where = "idmau = " + idMau;
            db.DeleteRecord("tbl_ttf_detail", _where);
            string _where2 = "idloaibai = 3 AND idmau = " + idMau;
            db.DeleteRecord("tbl_baiphantich", _where2);
            db.DeleteRecord("tbl_ttf_detail_section", _where);
            Response.Redirect("Default.aspx?module=Template&view=General&idMau=" + idMau);
        }
    }

    protected string GetNguoiPhanTich(string idMau)
    {
        string sql = "SELECT tbl_user.name FROM tbl_mau, tbl_user WHERE tbl_mau.nguoiphantich = tbl_user.id AND tbl_mau.id = " + idMau;
        db = new class_database();
        DataTable dt = db.GetDataTable(sql);
        string nameNguoiPhanTich = "";
        if (dt != null && dt.Rows.Count > 0)
        {
            nameNguoiPhanTich = dt.Rows[0]["name"].ToString();
        }
        return nameNguoiPhanTich;
    }

    protected void SetTitle(string idMau)
    {
        string sql = "SELECT tbl_user.name, tbl_mau.tenhamdiet FROM tbl_mau, tbl_user WHERE tbl_mau.nguoiphantich = tbl_user.id AND tbl_mau.id = " + idMau;
        db = new class_database();
        DataTable dt = db.GetDataTable(sql);
        if (dt != null && dt.Rows.Count > 0)
        {
            lblNguoiPhanTich.Text = "Người phân tích: " + dt.Rows[0]["name"].ToString();
            lblTenHamDiet.Text = "Tên hàm diệt: " + dt.Rows[0]["tenhamdiet"].ToString();
        }
    }

    private void LoadData(int typePart, string idMau)
    {
        string sql = "SELECT id, noidung, thongtin FROM tbl_ttf_detail WHERE idmau = " + idMau + " AND typeid = " + typePart;
        db = new class_database();
        DataTable dt = db.GetDataTable(sql);
        if (dt != null && dt.Rows.Count > 0)
        {
            if (typePart == 1)
            {
                gridThongTinCoBan.DataSource = dt;
                gridThongTinCoBan.DataBind();
            }
            else if (typePart == 2)
            {
                string sqlSection = "SELECT * FROM tbl_ttf_detail_section WHERE idmau = " + idMau;
                DataTable dtSection = db.GetDataTable(sqlSection);
                gridSection.DataSource = dtSection;
                gridSection.DataBind();
            }
            else if (typePart == 3)
            {
                gridVersion.DataSource = dt;
                gridVersion.DataBind();
            }
            else if (typePart == 4)
            {
                //rptPEHeader.DataSource = dt;
                //rptPEHeader.DataBind();
            }
            else if (typePart == 5)
            {
                gridImport.DataSource = dt;
                gridImport.DataBind();
            }
            else if (typePart == 6)
            {
                gridExport.DataSource = dt;
                gridExport.DataBind();
            }
            else if (typePart == 7)
            {
                gridViewPE.DataSource = dt;
                gridViewPE.DataBind();
            }
        }
    }

    protected void rptItemDataBond(object sender, RepeaterItemEventArgs e)
    {

    }








    protected void btnSubmitThongTinCoBan_Click(object sender, EventArgs e)
    {
        if (tbNoiDung1.Text == "" && tbThongTin1.Text == "")
        {
            class_database.Show("Không để trống cả 2 ô !!!");
        }
        else
        {
            db = new class_database();
            string[] _param = { "typeid", "noidung", "thongtin", "idmau" };
            string idMau = Convert.ToString(Session["idMau"]);
            string[] _value = { "1", tbNoiDung1.Text, tbThongTin1.Text, idMau };
            string[] _type = { "int", "string", "string", "int" };
            db.InsertRecord("tbl_ttf_detail", _param, _value, _type);
            tbNoiDung1.Text = "";
            tbThongTin1.Text = "";
            LoadData(1, idMau);
        }
    }

    protected void btnResetThongTinCoBan_Click(object sender, EventArgs e)
    {
        tbNoiDung1.Text = "";
        tbThongTin1.Text = "";
    }

    protected void gridThongTinCoBan_RowCancelling(object sender, GridViewCancelEditEventArgs e)
    {
        gridThongTinCoBan.EditIndex = -1;
        string idMau = Convert.ToString(Session["idMau"]);
        LoadData(1, idMau);
    }

    protected void gridThongTinCoBan_RowCommand(object sender, GridViewCommandEventArgs e)
    {

    }

    protected void gridThongTinCoBan_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        Label lblIDThongTinCoBan = gridThongTinCoBan.Rows[e.RowIndex].FindControl("lbIDThongTinCoBan") as Label;
        db = new class_database();
        string _where = "id = " + lblIDThongTinCoBan.Text.ToString();
        db.DeleteRecord("tbl_ttf_detail", _where);
        string idMau = Convert.ToString(Session["idMau"]);
        LoadData(1, idMau);
    }

    protected void gridThongTinCoBan_RowEditing(object sender, GridViewEditEventArgs e)
    {
        gridThongTinCoBan.EditIndex = e.NewEditIndex;
        string idMau = Convert.ToString(Session["idMau"]);
        LoadData(1, idMau);
    }

    protected void gridThongTinCoBan_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        Label lbIDThongTinCoBan = gridThongTinCoBan.Rows[e.RowIndex].FindControl("lbIDThongTinCoBan") as Label;
        TextBox tbNoiDungThongTinCoBan = gridThongTinCoBan.Rows[e.RowIndex].FindControl("tbNoiDungThongTinCoBan") as TextBox;
        TextBox tbThongTinThongTinCoBan = gridThongTinCoBan.Rows[e.RowIndex].FindControl("tbThongTinThongTinCoBan") as TextBox;
        string idMau = Convert.ToString(Session["idMau"]);
        db = new class_database();
        string[] _param = { "noidung", "thongtin" };
        string[] _value = { tbNoiDungThongTinCoBan.Text.ToString(), tbThongTinThongTinCoBan.Text.ToString() };
        string _where = "id = " + lbIDThongTinCoBan.Text;
        db.UpdateRecord("tbl_ttf_detail", _param, _value, _where);
        gridThongTinCoBan.EditIndex = -1;
        LoadData(1, idMau);
    }














    protected void btnSubmitSection_Click(object sender, EventArgs e)
    {
        if (tbSectionName.Text == "" && tbVirtualSize.Text == "" && tbVirtualAddress.Text == "" && tbRawSize.Text == "" && tbRawAddress.Text == "" && tbCharacter.Text == "")
        {
            class_database.Show("Không để trống cả 2 ô !!!");
        }
        else
        {
            db = new class_database();
            string[] _param = { "name", "virtualsize", "virtualaddress", "rawsize", "rawaddress", "characteristic", "idmau" };
            string idMau = Convert.ToString(Session["idMau"]);
            string[] _value = { tbSectionName.Text, tbVirtualSize.Text, tbVirtualAddress.Text, tbRawSize.Text, tbRawAddress.Text, tbCharacter.Text, idMau };
            string[] _type = { "string", "string", "string", "string", "string", "string", "int" };
            db.InsertRecord("tbl_ttf_detail_section", _param, _value, _type);

            string sqlGetRecordFinal = "SELECT id FROM tbl_ttf_detail_section ORDER BY id DESC LIMIT 1";
            DataTable dtGetID = db.GetDataTable(sqlGetRecordFinal);
            string idFinalRecord = dtGetID.Rows[0]["id"].ToString();

            string[] _param1 = { "typeid", "noidung", "thongtin", "idmau", "idsectionrecord" };
            string noidung = tbSectionName.Text;
            string thongtin = tbVirtualSize.Text + " " + tbVirtualAddress.Text + " " + tbRawSize.Text + " " + tbRawAddress.Text + " " + tbCharacter.Text;
            string[] _value1 = { "2", noidung, thongtin, idMau, idFinalRecord };
            string[] _type1 = { "int", "string", "string", "int", "int" };
            db.InsertRecord("tbl_ttf_detail", _param1, _value1, _type1);

            tbSectionName.Text = "";
            tbVirtualSize.Text = "";
            tbVirtualAddress.Text = "";
            tbRawSize.Text = "";
            tbRawAddress.Text = "";
            tbCharacter.Text = "";
            LoadData(2, idMau);
        }
    }

    protected void btnResetSection_Click(object sender, EventArgs e)
    {
        tbSectionName.Text = "";
        tbVirtualSize.Text = "";
        tbVirtualAddress.Text = "";
        tbRawSize.Text = "";
        tbRawAddress.Text = "";
        tbCharacter.Text = "";
    }

    protected void gridSection_RowCancelling(object sender, GridViewCancelEditEventArgs e)
    {
        gridSection.EditIndex = -1;
        string idMau = Convert.ToString(Session["idMau"]);
        LoadData(2, idMau);
    }

    protected void gridSection_RowCommand(object sender, GridViewCommandEventArgs e)
    {

    }

    protected void gridSection_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        Label lbIDSection = gridSection.Rows[e.RowIndex].FindControl("lbIDSection") as Label;
        db = new class_database();
        string _where = "id = " + lbIDSection.Text.ToString();
        db.DeleteRecord("tbl_ttf_detail_section", _where);
        string _where2 = "idsectionrecord = " + lbIDSection;
        db.DeleteRecord("tbl_ttf_detail", _where2);
        string idMau = Convert.ToString(Session["idMau"]);
        LoadData(2, idMau);
    }

    protected void gridSection_RowEditing(object sender, GridViewEditEventArgs e)
    {
        gridSection.EditIndex = e.NewEditIndex;
        string idMau = Convert.ToString(Session["idMau"]);
        LoadData(2, idMau);
    }

    protected void gridSection_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        Label lbIDSection = gridSection.Rows[e.RowIndex].FindControl("lbIDSection") as Label;
        TextBox tbSectionName = gridSection.Rows[e.RowIndex].FindControl("tbSectionName") as TextBox;
        TextBox tbVirtualSize = gridSection.Rows[e.RowIndex].FindControl("tbVirtualSize") as TextBox;
        TextBox tbVirtualAddress = gridSection.Rows[e.RowIndex].FindControl("tbVirtualAddress") as TextBox;
        TextBox tbRawSize = gridSection.Rows[e.RowIndex].FindControl("tbRawSize") as TextBox;
        TextBox tbRawAddress = gridSection.Rows[e.RowIndex].FindControl("tbRawAddress") as TextBox;
        TextBox tbCharacter = gridSection.Rows[e.RowIndex].FindControl("tbCharacter") as TextBox;
        string idMau = Convert.ToString(Session["idMau"]);
        db = new class_database();
        string[] _param = { "name", "virtualsize", "virtualaddress", "rawsize", "rawaddress", "characteristic" };
        string[] _value = { tbSectionName.Text.ToString(), tbVirtualSize.Text.ToString(), tbVirtualAddress.Text.ToString(), tbRawSize.Text.ToString(), tbRawAddress.Text.ToString(), tbCharacter.Text.ToString() };
        string _where = "id = " + lbIDSection.Text;
        db.UpdateRecord("tbl_ttf_detail_section", _param, _value, _where);

        string noidung = tbSectionName.Text;
        string thongtin = tbVirtualSize.Text + " " + tbVirtualAddress.Text + " " + tbRawSize.Text + " " + tbRawAddress.Text + " " + tbCharacter.Text;
        string[] _param2 = { "noidung", "thongtin" };
        string[] _value2 = { noidung, thongtin };
        string _where2 = "idsectionrecord = " + lbIDSection.Text;
        db.UpdateRecord("tbl_ttf_detail", _param2, _value2, _where2);

        gridSection.EditIndex = -1;
        LoadData(2, idMau);
    }























    protected void btnSubmitVersion_Click(object sender, EventArgs e)
    {
        if (tbNoiDung3.Text == "" && tbThongTin3.Text == "")
        {
            class_database.Show("Không để trống cả 2 ô !!!");
        }
        else
        {
            db = new class_database();
            string[] _param = { "typeid", "noidung", "thongtin", "idmau" };
            string idMau = Convert.ToString(Session["idMau"]);
            string[] _value = { "3", tbNoiDung3.Text, tbThongTin3.Text, idMau };
            string[] _type = { "int", "string", "string", "int" };
            db.InsertRecord("tbl_ttf_detail", _param, _value, _type);
            tbNoiDung3.Text = "";
            tbThongTin3.Text = "";
            LoadData(3, idMau);
        }
    }

    protected void btnResetVersion_Click(object sender, EventArgs e)
    {
        tbNoiDung3.Text = "";
        tbThongTin3.Text = "";
    }

    protected void gridVersion_RowCancelling(object sender, GridViewCancelEditEventArgs e)
    {
        gridVersion.EditIndex = -1;
        string idMau = Convert.ToString(Session["idMau"]);
        LoadData(3, idMau);
    }

    protected void gridVersion_RowCommand(object sender, GridViewCommandEventArgs e)
    {

    }

    protected void gridVersion_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        Label lblIDVersion = gridVersion.Rows[e.RowIndex].FindControl("lbIDVersion") as Label;
        db = new class_database();
        string _where = "id = " + lblIDVersion.Text.ToString();
        db.DeleteRecord("tbl_ttf_detail", _where);
        string idMau = Convert.ToString(Session["idMau"]);
        LoadData(3, idMau);
    }

    protected void gridVersion_RowEditing(object sender, GridViewEditEventArgs e)
    {
        gridVersion.EditIndex = e.NewEditIndex;
        string idMau = Convert.ToString(Session["idMau"]);
        LoadData(3, idMau);
    }

    protected void gridVersion_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        Label lbIDVersion = gridVersion.Rows[e.RowIndex].FindControl("lbIDVersion") as Label;
        TextBox tbNoiDungVersion = gridVersion.Rows[e.RowIndex].FindControl("tbNoiDungVersion") as TextBox;
        TextBox tbThongTinVersion = gridVersion.Rows[e.RowIndex].FindControl("tbThongTinVersion") as TextBox;
        string idMau = Convert.ToString(Session["idMau"]);
        db = new class_database();
        string[] _param = { "noidung", "thongtin" };
        string[] _value = { tbNoiDungVersion.Text.ToString(), tbThongTinVersion.Text.ToString() };
        string _where = "id = " + lbIDVersion.Text;
        db.UpdateRecord("tbl_ttf_detail", _param, _value, _where);
        gridVersion.EditIndex = -1;
        LoadData(3, idMau);
    }















    protected void btnSubmitImport_Click(object sender, EventArgs e)
    {
        if (tbNoiDung5.Text == "" && tbThongTin5.Text == "")
        {
            class_database.Show("Không để trống cả 2 ô !!!");
        }
        else
        {
            db = new class_database();
            string[] _param = { "typeid", "noidung", "thongtin", "idmau" };
            string idMau = Convert.ToString(Session["idMau"]);
            string[] _value = { "5", tbNoiDung5.Text, tbThongTin5.Text, idMau };
            string[] _type = { "int", "string", "string", "int" };
            db.InsertRecord("tbl_ttf_detail", _param, _value, _type);
            tbNoiDung5.Text = "";
            tbThongTin5.Text = "";
            LoadData(5, idMau);
        }
    }

    protected void btnResetImport_Click(object sender, EventArgs e)
    {
        tbNoiDung5.Text = "";
        tbThongTin5.Text = "";
    }

    protected void gridImport_RowCancelling(object sender, GridViewCancelEditEventArgs e)
    {
        gridImport.EditIndex = -1;
        string idMau = Convert.ToString(Session["idMau"]);
        LoadData(5, idMau);
    }

    protected void gridImport_RowCommand(object sender, GridViewCommandEventArgs e)
    {

    }

    protected void gridImport_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        Label lblIDImport = gridImport.Rows[e.RowIndex].FindControl("lbIDImport") as Label;
        db = new class_database();
        string _where = "id = " + lblIDImport.Text.ToString();
        db.DeleteRecord("tbl_ttf_detail", _where);
        string idMau = Convert.ToString(Session["idMau"]);
        LoadData(5, idMau);
    }

    protected void gridImport_RowEditing(object sender, GridViewEditEventArgs e)
    {
        gridImport.EditIndex = e.NewEditIndex;
        string idMau = Convert.ToString(Session["idMau"]);
        LoadData(5, idMau);
    }

    protected void gridImport_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        Label lbIDImport = gridImport.Rows[e.RowIndex].FindControl("lbIDImport") as Label;
        TextBox tbNoiDungImport = gridImport.Rows[e.RowIndex].FindControl("tbNoiDungImport") as TextBox;
        TextBox tbThongTinImport = gridImport.Rows[e.RowIndex].FindControl("tbThongTinImport") as TextBox;
        string idMau = Convert.ToString(Session["idMau"]);
        db = new class_database();
        string[] _param = { "noidung", "thongtin" };
        string[] _value = { tbNoiDungImport.Text.ToString(), tbThongTinImport.Text.ToString() };
        string _where = "id = " + lbIDImport.Text;
        db.UpdateRecord("tbl_ttf_detail", _param, _value, _where);
        gridImport.EditIndex = -1;
        LoadData(5, idMau);
    }















    protected void btnSubmitExport_Click(object sender, EventArgs e)
    {
        if (tbNoiDung6.Text == "" && tbThongTin6.Text == "")
        {
            class_database.Show("Không để trống cả 2 ô !!!");
        }
        else
        {
            db = new class_database();
            string[] _param = { "typeid", "noidung", "thongtin", "idmau" };
            string idMau = Convert.ToString(Session["idMau"]);
            string[] _value = { "6", tbNoiDung6.Text, tbThongTin6.Text, idMau };
            string[] _type = { "int", "string", "string", "int" };
            db.InsertRecord("tbl_ttf_detail", _param, _value, _type);
            tbNoiDung6.Text = "";
            tbThongTin6.Text = "";
            LoadData(6, idMau);
        }
    }

    protected void btnResetExport_Click(object sender, EventArgs e)
    {
        tbNoiDung6.Text = "";
        tbThongTin6.Text = "";
    }

    protected void gridExport_RowCancelling(object sender, GridViewCancelEditEventArgs e)
    {
        gridExport.EditIndex = -1;
        string idMau = Convert.ToString(Session["idMau"]);
        LoadData(6, idMau);
    }

    protected void gridExport_RowCommand(object sender, GridViewCommandEventArgs e)
    {

    }

    protected void gridExport_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        Label lblIDExport = gridExport.Rows[e.RowIndex].FindControl("lbIDExport") as Label;
        db = new class_database();
        string _where = "id = " + lblIDExport.Text.ToString();
        db.DeleteRecord("tbl_ttf_detail", _where);
        string idMau = Convert.ToString(Session["idMau"]);
        LoadData(6, idMau);
    }

    protected void gridExport_RowEditing(object sender, GridViewEditEventArgs e)
    {
        gridExport.EditIndex = e.NewEditIndex;
        string idMau = Convert.ToString(Session["idMau"]);
        LoadData(6, idMau);
    }

    protected void gridExport_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        Label lbIDExport = gridExport.Rows[e.RowIndex].FindControl("lbIDExport") as Label;
        TextBox tbNoiDungExport = gridExport.Rows[e.RowIndex].FindControl("tbNoiDungExport") as TextBox;
        TextBox tbThongTinExport = gridExport.Rows[e.RowIndex].FindControl("tbThongTinExport") as TextBox;
        string idMau = Convert.ToString(Session["idMau"]);
        db = new class_database();
        string[] _param = { "noidung", "thongtin" };
        string[] _value = { tbNoiDungExport.Text.ToString(), tbThongTinExport.Text.ToString() };
        string _where = "id = " + lbIDExport.Text;
        db.UpdateRecord("tbl_ttf_detail", _param, _value, _where);
        gridExport.EditIndex = -1;
        LoadData(6, idMau);
    }
















    protected void btnSubmitPE_Click(object sender, EventArgs e)
    {
        if (tbNoiDung7.Text == "" && tbThongTin7.Text == "")
        {
            class_database.Show("Không để trống cả 2 ô !!!");
        }
        else
        {
            db = new class_database();
            string[] _param = { "typeid", "noidung", "thongtin", "idmau" };
            string idMau = Convert.ToString(Session["idMau"]);
            string[] _value = { "7", tbNoiDung7.Text, tbThongTin7.Text, idMau };
            string[] _type = { "int", "string", "string", "int" };
            db.InsertRecord("tbl_ttf_detail", _param, _value, _type);
            tbNoiDung7.Text = "";
            tbThongTin7.Text = "";
            LoadData(7, idMau);
        }
    }

    protected void btnResetPE_Click(object sender, EventArgs e)
    {
        tbNoiDung7.Text = "";
        tbThongTin7.Text = "";
    }

    protected void gridViewPE_RowCancelling(object sender, GridViewCancelEditEventArgs e)
    {
        gridViewPE.EditIndex = -1;
        string idMau = Convert.ToString(Session["idMau"]);
        LoadData(7, idMau);
    }

    protected void gridViewPE_RowCommand(object sender, GridViewCommandEventArgs e)
    {

    }

    protected void gridViewPE_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        Label lblIDPE = gridViewPE.Rows[e.RowIndex].FindControl("lbIDPE") as Label;
        db = new class_database();
        string _where = "id = " + lblIDPE.Text.ToString();
        db.DeleteRecord("tbl_ttf_detail", _where);
        string idMau = Convert.ToString(Session["idMau"]);
        LoadData(7, idMau);
    }

    protected void gridViewPE_RowEditing(object sender, GridViewEditEventArgs e)
    {
        gridViewPE.EditIndex = e.NewEditIndex;
        string idMau = Convert.ToString(Session["idMau"]);
        LoadData(7, idMau);
    }

    protected void gridViewPE_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        Label lbIDPE = gridViewPE.Rows[e.RowIndex].FindControl("lbIDPE") as Label;
        TextBox tbNoiDungPE = gridViewPE.Rows[e.RowIndex].FindControl("tbNoiDungPE") as TextBox;
        TextBox tbThongTinPE = gridViewPE.Rows[e.RowIndex].FindControl("tbThongTinPE") as TextBox;
        string idMau = Convert.ToString(Session["idMau"]);
        db = new class_database();
        string[] _param = { "noidung", "thongtin" };
        string[] _value = { tbNoiDungPE.Text.ToString(), tbThongTinPE.Text.ToString() };
        string _where = "id = " + lbIDPE.Text;
        db.UpdateRecord("tbl_ttf_detail", _param, _value, _where);
        gridViewPE.EditIndex = -1;
        LoadData(6, idMau);
    }



}
